package my.example.samplegridview.modal;

import java.util.Vector;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

public class product_option {
	public static final String Table = "o2s_product_option";
    public static final Uri    CONTENT_URI = Uri.parse("content://o2s.contentprovider.datacontentprovider/product_option");
    public static final String SQLCREATE = "CREATE TABLE 'o2s_product_option' ( " +
    										"'product_option_id' INTEGER PRIMARY KEY, " +
    										"'product_id' int(11) NOT NULL , " +
    										"'sort_order' int(3) NOT NULL DEFAULT '0' );";
    
    private String product_option_id;
    private String product_id;
    private String sort_order;
    private Vector<product_option_value> product_option_values;
    private product_option_description prooptiondescription;
    private int selectedoption;
    
    private Context mContext;
    
    public product_option(Context mContext){
    	prooptiondescription = new product_option_description();
    	this.mContext = mContext;
    	product_option_values = new Vector<product_option_value>();
    	selectedoption = -1;
    }
    
    public product_option(Context mContext, String product_id){
    	prooptiondescription = new product_option_description();
    	this.mContext = mContext;
    	this.product_id = product_id;
    	product_option_values = new Vector<product_option_value>();
    	getProduct_option_values();
    	selectedoption = -1;
    }
    
	public String getProduct_option_id() {
		return product_option_id;
	}
	public void setProduct_option_id(String product_option_id) {
		this.product_option_id = product_option_id;
	}
	public String getProduct_id() {
		return product_id;
	}
	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}
	public String getSort_order() {
		return sort_order;
	}
	public void setSort_order(String sort_order) {
		this.sort_order = sort_order;
	}
	
	public product_option_description getProoptiondescription() {
		String[] arg = {this.product_option_id};
		Cursor c = mContext.getContentResolver().query(product_option_description.CONTENT_URI, null, "product_option_id=?", arg, null);
		while(c.moveToNext()){
			prooptiondescription.setProduct_option_id(this.product_option_id);
			prooptiondescription.setLanguage_id(String.valueOf(c.getInt(1)));
			prooptiondescription.setProduct_id(String.valueOf(c.getInt(2)));
			prooptiondescription.setName(c.getString(3));
		}
		c.close();
		return prooptiondescription;
	}

	public Vector<product_option_value> getProduct_option_values() {
		String[] arg1 = {product_option_id};
		Cursor c1 = mContext.getContentResolver().query(product_option_value.CONTENT_URI, null, "product_option_id=?", arg1, null);
		while(c1.moveToNext()){
			product_option_value pov = new product_option_value(mContext);
			pov.setProduct_option_value_id(String.valueOf(c1.getInt(0)));
			pov.setProduct_option_id(product_option_id);
			pov.setProduct_id(String.valueOf(c1.getInt(2)));
			pov.setQuantity(String.valueOf(c1.getInt(3)));
			pov.setSubtract(String.valueOf(c1.getInt(4)));
			pov.setPrice(String.valueOf(c1.getInt(5)));
			pov.setPrefix(c1.getString(6));
			pov.setSort_order(String.valueOf(c1.getInt(7)));
			pov.getProoptionvaluedescription();
			product_option_values.add(pov);
		}
		c1.close();
		return product_option_values;
	}	
	
	public Vector<product_option_value> getProduct_option_values(boolean in) {
		return product_option_values;
	}

	public void setSelectedoption(int selectedoption) {
		this.selectedoption = selectedoption;
	}

	public int getSelectedoption() {
		return selectedoption;
	}
}
